package com.easywan.core;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.core.ConfigurableObjectInputStream;

public class DBConnection {
	private static String url ;
	private static String name;
	private static String pwd;
	private static  String driver = "com.mysql.jdbc.Driver";
	//private static  Connection con;
	static{
			try {
				url = Config.get("url");
				name = Config.get("username");
				pwd = Config.get("password");
				
				Class.forName(driver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	public static Connection getConnect() throws SQLException{
		Connection conn = DriverManager.getConnection(url,name,pwd);
		return conn;
	}
	public static void close(Connection conn,ResultSet rs, PreparedStatement pstmt) {
		close(rs);
		close(pstmt);
		close(conn);
	}
	public static void close(Connection conn){
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void close(ResultSet conn){
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void close(PreparedStatement rs){
		try {
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
